import { Response } from '@/utils/request';

const useRes = <T extends Response>(
  res: T,
  callbackSuccess?: (data: T extends { data: infer D } ? D : unknown) => void,
  callbackErr?: (_res: T) => void
) => {
  if (res.code == 'ok') {
    callbackSuccess?.(res.data);
  } else {
    if (callbackErr) {
      callbackErr(res);
    } else {
      // message.error(res.message);
    }
  }
};

export default useRes;
